#include "PWSetup.h"
#include "PWGame.h"


//Game object struct
struct gameObject{
	D3DXVECTOR3 position;
	float speed;
	bool moving;
	float durability;
	float rotation;
};
	
class CDirectXFramework{
public:
	CDirectXFramework(void);
	~CDirectXFramework(void);
	void Init(HWND& hWnd, HINSTANCE& hInst, bool bWindowed);
	//Checks if an object is on the screen
	bool OnScreen(float x, float y);
	//Checks if sprites collide
	bool Collide(gameObject obj1, gameObject obj2, D3DXIMAGE_INFO obj1_info, D3DXIMAGE_INFO obj2_info);
	//Sets all level one variables
	void setLevelOne();
	//Sets all level two variables
	void setLevelTwo();
	//Set Minions
	void setMinions(int start, int end, float x, float y,float speed,int dur, bool moving);
	//Enemy move
	void minionSpawn(int start, int end,int dx, int dy,int angle);
	//Update player data
	void updatePlayer();
	//Update level 1 boss and minions
	void minionShoot();
	void updateLV1Boss(float time);
	void updateLV1Minions(float time);
	//Update level 2 boss and minions
	void updateLV2Boss(float time);
	void updateLV2Minions(float time);
	//Updates all level data
	void updateLevel();
	//Updates collisions on level
	void updateBossCollision();
	//Updates collision data
	void updateCollision();
	//checks if the player is hit, if hit go invul for 2 seconds
	void playerDie();
	//Updates the game
	void updateGame();
	//Update menu page
	void updateMenu();
	//Update title page	
	void updateTitle();
	//Update credits page
	void updateCredits();
	//update the help page
	void updateHelp();
	//All updates end up here
	void Update();
	
	//Function to render Objects
	void renderObject(float x, float y,float scaleX, float scaleY,float rotation, IDirect3DTexture9& tex,D3DXIMAGE_INFO info, DWORD color);
	//Function to render Background
	void renderBG(float x, float y,float scale, IDirect3DTexture9& tex,D3DXIMAGE_INFO info, DWORD color);
	//Renders player
	void renderPlayer();
	//Renders level one
	void renderLevelOne();
	//Renders level two
	void renderLevelTwo();
	//Renders the game state
	void renderGame();
	void renderMenu();	//Renders menu page
	void renderTitle(); //Renders title page
	void renderCredits(); //Renders credits page
	void renderHelp(); //Renders help page
	void Render(); //All renders end up here
	
	//Releases all objects and devices
	void Shutdown();

	HWND				m_hWnd;			// Handle to the window
	bool				m_bVsync;		// Boolean for vertical syncing

	IDirect3D9*			m_pD3DObject;	// Direct3D 9 Object
	IDirect3DDevice9*	m_pD3DDevice;	// Direct3D 9 Device
	D3DCAPS9			m_D3DCaps;		// Device Capabilities
	
	ID3DXSprite*		m_pD3DSprite;	// Sprite Object
	
	//Title page texture and info
	IDirect3DTexture9*	m_pTexture;		
	D3DXIMAGE_INFO		m_imageInfo;	
	
	//Menu page texture and info
	IDirect3DTexture9*	m_pMenuTexture;
	D3DXIMAGE_INFO		m_menuInfo;
	
	//Player texture and info
	IDirect3DTexture9*	m_ptriTexture;
	D3DXIMAGE_INFO		m_triInfo;
	
	//Projectile texture and info
	IDirect3DTexture9*	m_pbulletTexture;
	D3DXIMAGE_INFO		m_bulletInfo;
	
	//Level one minion texture and info
	IDirect3DTexture9*	m_pbRectTexture;
	D3DXIMAGE_INFO		m_RectInfo;
	
	//Level one Boss texture and info
	IDirect3DTexture9*	m_LV1BossTexture;
	D3DXIMAGE_INFO		m_LV1BossInfo;
	IDirect3DTexture9*	m_LV1BossProjTexture;
	D3DXIMAGE_INFO		m_LV1BossProjInfo;
	
	//Level one Boss texture and info
	IDirect3DTexture9*	m_LV2BossTexture;
	D3DXIMAGE_INFO		m_LV2BossInfo;
	IDirect3DTexture9*	m_LV2BossProjTexture;
	D3DXIMAGE_INFO		m_LV2BossProjInfo;
	IDirect3DTexture9*	m_LV2BossLaserTexture;
	D3DXIMAGE_INFO		m_LV2BossLaserInfo;
	
	//Level two minion texture and info
	IDirect3DTexture9*	m_LV2MinionTexture;
	D3DXIMAGE_INFO		m_LV2MinionInfo;
	

	//Background texture and info
	IDirect3DTexture9*	m_BGTexture[2];
	D3DXIMAGE_INFO		m_BGInfo[2];

	IDirect3DTexture9*	m_LV1Texture;
	D3DXIMAGE_INFO		m_LV1Info;

	IDirect3DTexture9*	m_creditsTexture;
	D3DXIMAGE_INFO		m_creditsInfo;
	
	IDirect3DTexture9*	m_gOverTexture;
	D3DXIMAGE_INFO		m_gOverInfo;

	//Help page texture and info
	IDirect3DTexture9*	m_helpTexture;
	D3DXIMAGE_INFO		m_helpInfo;
	
	//Help page texture and info
	IDirect3DTexture9*	m_HPTex;
	D3DXIMAGE_INFO		m_HPInfo;

	//Direct Input
	IDirectInput8* m_pDIObject;
	LPDIRECTINPUTDEVICE8W m_pDIKeyboard;
	LPDIRECTINPUTDEVICE8W m_pDIMouse;
	DIMOUSESTATE2 mouseState;
	char buffer[256];
	BYTE				m_bKeyDown[256];

	//Direct Font
	ID3DXFont*			m_pD3DFont;	

	// Menu state and score
	char state;
	int score;
	
	//Floats for time and frames
	double start_time,tAfterStart,current;
	float frames,last, currTime,lastTime,elapsedTime;
	
	
	//Projectile objects
	gameObject playerShot[MAX_SHOTS];
	gameObject enemyShot[MAX_SHOTS];
	gameObject bossShot[MAX_SHOTS];
	gameObject BossLaser;
	
	//game objects
	gameObject minions[MAX_ENEMIES_LVONE];
	gameObject LV1_Boss, LV2_Boss;
	gameObject player;

	//Player variables
	int player_shots,enemy_shot_counter;
	int charState;
	int tempColor,tempCounter;
	double invulTimer;
	bool hit,invul;	
	//shots and color variables
	float lastShot, currentShot, betShot;
	float r_char,g_char,b_char;
	float lastColor, currentColor, betColor;
	DWORD playerColor, enemyColor, defaultColor;
	D3DXVECTOR3 shotTarget,shotMagnitude[MAX_SHOTS],shotMagnitude2[MAX_SHOTS];
	int temp[MAX_SHOTS];
	//Level variables
	double timeLV;
	int level;
	int levelState;
	//Level One varables
	double LV1_StartSpawn, LV1_Interval,LV1_Start;
	double LV1_Boss_spawn, LV1_StartDraw;
	int LV1_Counter, BossState,BossCounter;
	double BossNow, BossInterval;
	bool bossTrigger;
	//Level Two variables
	bool lvTrigger;
	double LV2_Start, LV2_StartSpawn, LV2_Interval, LV2_Boss_spawn, LV2_StartDraw;
	double LV2Boss_Interval,LV2Boss_Shots;
	int charge, laser, startup;
	double laserStart;
	//Background variables
	D3DXVECTOR3 BGPos, BGPos2;
	float BGspeed;

	//Mouse coord
	POINT mousePos;
	
	//Sound Variables
	FMOD::System *system;
	FMOD_RESULT result;
	unsigned int version;
	int numdrivers;
	FMOD_SPEAKERMODE speakermode;
	FMOD_CAPS caps;
	char name[256];
	
	FMOD::Sound*		playerShoot;
	FMOD::Sound*		enemyShoot;
	FMOD::Sound*		bossShoot;
	FMOD::Sound*		enemyHit;
	FMOD::Sound*		playerHit;
	FMOD::Sound*		bossExplosion;
	FMOD::Sound*		select;
	FMOD::Sound*		intro;
	FMOD::Sound*		levelOneBGM;
	FMOD::Sound*		levelTwoBGM;
	FMOD::Channel*		pShootChannel;
	FMOD::Channel*		eShootChannel;
	FMOD::Channel*		bShootChannel;
	FMOD::Channel*		eHitChannel;
	FMOD::Channel*		bExplosionChannel;
	FMOD::Channel*		selectChannel;
	FMOD::Channel*		introChannel;
	FMOD::Channel*		LV1BGMChannel;
	FMOD::Channel*		LV2BGMChannel;
	FMOD::Channel*		pHitChannel;
	
	
	bool paused;
private:

};
